1. Field of the Invention
The present invention relates to an image data compressing apparatus and image data compressing method which are used to compress image data, and, more particularly, to an image data compressing apparatus and image data compressing method which have a generated-code-amount control function to control the amount of generated codes.
2. Description of the Related Art
International standards for image compression include JPEG (Joint Photographic Expert Group) and MPEG (Moving Picture Expert Group).
JPEG aims at compressing a still image. Its encoding scheme for color still images has already been determined and will be approved as the international standard. Chips for JPEG have been commercialized and boards having such a chip mounted thereon are appearing on the market.
The JPEG algorithm is generally classified into two compressing systems. The first system is based on DCT (Discrete Cosine Transform), and the second system is a spatial system which performs DPCM (Differential PCM) in two-dimensional space. As the DCT system includes quantization, it is a non-information preserving coding that cannot generally restore the original image completely. But, the DCT system can provide a sufficient decoded image quality with few bits, and is the base of this algorithm. The spatial system, on the other hand, is an information preserving coding that can completely restore the original image though the compression ratio is small, and is added as a standard system to realize this characteristic.
The DCT system is further classified into a baseline system which has the essential function, and an extended system which has an optional function. As an additional system, there is a hierarchical system which is the combination of the above two systems to accomplish progressive buildup.
The baseline system has the minimum function all coders/decoders to accomplish what the DCT system should have, and is an algorithm based on ADCT (Adaptive Discrete Cosine Transform) coding.
In the image compression in the baseline system, image data is processed in blocks each of 8.times.8 pixels. The processes include:
(1) Two-dimensional DCT transform PA1 (2) Quantization of DCT coefficients PA1 (3) Entropy coding PA1 Mode 1: Huffman coding is performed on input data, and the number of bits generated for the DC component of each block is written in the DC code amount memory 15 at that time. The number of bits for the AC components is written in the AC code amount memory 16. PA1 Mode 2: Huffman coding is performed on input data. In this coding, a predicted value for the amount of generated codes that is yielded by both the DC component of each block, written in the DC code amount memory 15, and the AC components, written in the AC code amount memory 16, is compared with the amount of actually generated codes, and if the actual amount of generated codes is greater than the predicted value, an EOB (End of Block) to make bits following a certain value all zero is generated, then the coding for that block is terminated. The number of the remaining bits is added to the predicted value for the next block. PA1 i) First, prepare proper quantization tables and write them in the respective quantization table RAMs 21 and 22. PA1 ii) Then, perform DCT.fwdarw.quantization.fwdarw.Huffman coding (mode 1). PA1 iii) Refer to the total amount of generated codes stored in the TAGC memory 17, prepare new proper quantization tables based on that value, and write them in the respective quantization table RAMs 21 and 22 again. PA1 iv) Then, perform DCT.fwdarw.quantization.fwdarw.Huffman coding (mode 1) again. PA1 v) Prepare quantization tables which generate the target amount of generated codes, based on the total amount of generated codes obtained in ii) and the current total amount of generated codes, and write the tables in the quantization table RAMs 21 and 22. Subtract the total amount of codes generated by the DC component and the EOB length of each block from the target amount of generated codes and acquire the ratio of the resultant value to the total amount of codes generated by the AC components. Then, multiply the ratio by the amount of codes generated by the AC components of each block minus the EOB length, add the amount of codes generated by the DC component of each block plus the EOB length to the multiplication result, and write the resultant value as a predicted value for the amount of generated codes for each block in the AC code amount memory 16. PA1 vi) Then, perform DCT.fwdarw.quantization.fwdarw.Huffman coding (mode 2). PA1 transform means for transforming image data; PA1 quantization table storage means for storing plural types of quantization tables used in quantization; PA1 quantizing means for quantizing a signal output from the transform means based on the quantization tables; and PA1 coding means for coding components quantized by the quantizing means in accordance with a predicted amount of generated codes of each block, PA1 whereby the plural types of quantization tables are used to predict a change in an amount of generated codes caused by changing the quantization tables in a first compression and compression to a target amount of codes is performed in a second compression. PA1 transform means for transforming image data; PA1 quantization table storage means for storing quantization tables used in quantization; PA1 quantizing means for quantizing a signal output from the transform means based on the quantization tables; PA1 coding means for coding components quantized by the quantizing means in accordance with a predicted amount of generated codes of each block; PA1 code amount storage means for storing amounts of codes of DC components and AC components generated in individual blocks at a coding time; PA1 total-amount-of-generated-code computing means for computing total amounts of generated codes of the DC components and AC components; PA1 total-amount-of-generated-code storage means for storing the total amounts of generated codes computed by the total-amount-of-generated-code computing means; and PA1 at least one of block distributing means including,
In the two-dimensional DCT transform, spatial data is converted into frequency data and 64 DCT coefficients are produced. In this case, the color components are Y, CB and CR. The left end coefficient in a matrix of the 64 coefficients is called a DC component, which is an average value of block data. The remaining 63 coefficients are called AC components.
In the quantization of the DCT coefficients, the DCT coefficients are linearly quantized by a quantizer using a quantization matrix where quantization step sizes different for the individual coefficients are set. It is to be noted that to control the amount of generated codes or the quality of an encoded image, a quantization matrix multiplied by an externally specified coefficient (scaling factor) stored in a reference table is used as an actual matrix value in the quantization. The 64 DCT coefficients are quantized to be integer values referring to the table. This quantization results in non-reversible compression. The contents of the reference table that is used in quantization are not specified in JPEG. The quantization table is prepared in consideration of human visual characteristics. As man is not so sensitive to visual information of high-frequency components, such high-frequency components will be quantized roughly.
In the entropy encoding, the difference between the DC component in a block and the quantized DC component in the left-hand adjoining block is computed and encoded first. This scheme is called DPCM. The AC components are transformed to have a linear arrangement by zigzag scanning. In entropy encoding in the baseline system, a Huffman coding scheme is employed. In the Huffman coding, it is determined whether or not each coefficient is zero, and the length of consecutive zero coefficients is reckoned as run length when a non-zero coefficient is detected, it is subjected to two-dimensional Huffman coding by combining the result of its quantization and the run length of the preceding zero coefficients. While Huffman coding of DC/AC components is based on a given Huffman coding table, the quantization matrix and Huffman coding table have no default values to provide the optimal performance matching with the conditions for the usage, and are transferred from a coder to a decoder when needed.
FIG. 13 presents a block diagram of a conventional image data compressing apparatus 10 that is based on the JPEG algorithm. In FIG. 13, reference numeral 11 denotes a frame memory where data of an original image is held. The image data in the frame memory 11 is output to a DCT computation section 12. The DCT computation section 12 performs DCT computation on the received data block by block and outputs the result to a quantizer 13. The quantizer 13 performs quantization on the computed data in accordance with the values on quantization tables (see FIGS. 15 and 16) in a quantization table RAM or a Huffman coder 14. The Huffman coder 14 performs Huffman coding on the output data of the quantizer 13 using a DC code amount memory 15 and an AC code amount memory 16. The total amount of codes generated is stored in a total-amount-of-generated-code (TAGC) memory 17. A CPU 18 performs the general control of those units, and performs control to prepare the optimal quantization tables and predict the amount of generated codes of each block. The latter two processes will be described later.
The Huffman coder 14 performs Huffman coding in the following two modes.
FIG. 14 presents a block diagram of the quantizer 13. Referring to FIG. 14, the quantizer 13 comprises a quantization table RAM 21 for storing a Y (luminance information) quantization table (FIG. 15), a quantization table RAM 22 for storing a C (color information) quantization table (FIG. 16), and a multiplier 23 for obtaining a division value by dividing each frequency component yielded in the DCT computation, by a value in each quantization table (i.e., by multiplying the former component by a reciprocal of the latter value to accomplish the division) to accomplish quantization while changing the weighting. The quantization table RAMs 21 and 22 respectively correspond to the Y component and the R-Y and B-Y components.
FIG. 15 shows the Y quantization table, and FIG. 16 the C quantization table. Actually, the reciprocal values of those in the quantization tables are written in the quantization table RAMs 21 and 22. The quantizer 13 outputs the multiplication result.
The image data compressing apparatus 10 with the above-described structure prepares the optimal quantization tables and predicts the amount of generated codes for each block in the following manner.
However, the conventional image data compressing apparatus 10 controls the amount of generated codes in the above-described schemes ii), iv) and vi), so that the sequence of "DCT.fwdarw.quantization.fwdarw.Huffman coding" should be executed three times, which takes much time.